/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jsf.bean.client;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import model.client.Country;

/**
 *
 * @author Administrator
 */
@ManagedBean
@RequestScoped
public class CountryBean_c {
    Connection conn;
    private List<Country> lstCountries;
    //Table name constant
    private final String TABLE_ACCOUNTS = "Accounts";
    private final String TABLE_ACCOUNTS_DETAILS = "Account_Details";
    private final String TABLE_COUNTRY = "Countries";
    private final String TABLE_CITIES = "Cities";
    private final String TABLE_PAYMENT_TYPE = "Payment_Types";
    //Field name constant
    private final String CITY_ID = "City_Id";
    private final String CITY_NAME = "City_Name";
    private final String COUNTRY_ID = "Country_Id";
    private final String COUNTRY_STATUS = "Country_Status";
    private final String COUNTRY_NAME = "Country_Name";
    
    public List<Country> listCountries() throws SQLException {
        PreparedStatement pst = conn.prepareStatement("SELECT * FROM " + TABLE_COUNTRY);
        ResultSet rs = pst.executeQuery();

        lstCountries = new ArrayList<Country>();
        while (rs.next()) {
            lstCountries.add(new Country(rs.getInt(COUNTRY_ID), rs.getBoolean(COUNTRY_STATUS), rs.getString(COUNTRY_NAME)));
        }

        return lstCountries;
    }
    /**
     * Creates a new instance of CountryBean_c
     */
    public CountryBean_c() throws SQLException, ClassNotFoundException {
        conn = JDBCUtil.MyConn.getConnection();
    }
    
}
